//: [Previous](@previous)

/*:
 ### LeetCode上第203号问题：Remove Linked List Elements
 ```
 删除链表中等于给定值 val 的所有节点。
 示例: 
 输入: 1->2->6->3->4->5->6, val = 6
 输出: 1->2->3->4->5
 ```
 */

var link = SinglyLinkedList()
link.appendToTail(1)
//link.appendToTail(2)
//link.appendToTail(6)
//link.appendToTail(3)
//link.appendToTail(4)
//link.appendToTail(5)
//link.appendToTail(6)

func Solution(_ head: ListNode?, _ val: Int) -> ListNode? {
    let dummyHead = ListNode(0)
    dummyHead.next = head
    
    var temp = dummyHead
    
    while temp.next != nil {
        
        if temp.next!.val == val {
            temp.next = temp.next!.next
        } else {
            temp = temp.next!
        }
        
    }
    
    return dummyHead.next
}
print(link)
link.head = Solution(link.head, 1)
print(link) 

//: [Next](@next)
